package com.cn.xly2023.service;

import com.cn.xly2023.mapper.CsMapper;
import com.cn.xly2023.mapper.GoodsMapper;
import com.cn.xly2023.pojo.Cs;
import com.cn.xly2023.pojo.Goods;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CsService implements Serializable {
    @Resource
    private CsMapper csMapper;


    public Map<String,Object> selectById(Integer id){
        HashMap<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","查询成功!");
        map.put("data",csMapper.selectById(id));
        return map;
    }


    public Map<String,Object> selectAll(){
        List<Cs> csList = csMapper.selectAll();
        HashMap<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","登陆成功!");
        map.put("count",csList.size());
        map.put("data",csList);
        return map;
    }

    public Map<String,Object> selectByPage( Integer page, Integer limit,String csname,String gender){
        Integer index = (page - 1) *limit;
        List<Cs> csList = csMapper.selectByPage(index,limit,csname,gender);
        HashMap<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","登陆成功!");
        map.put("count",csMapper.selectCount(csname,gender));
        map.put("data",csList);
        return map;
    }



    public Map<String,Object> insert(Cs cs){
        csMapper.insert(cs);
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","插入成功!");
        map.put("data",cs);
        return map;
    }

    public Map<String,Object> deleteById(Integer id){
        csMapper.deleteById(id);
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","删除成功!");
        return map;
    }

//    public Map<String,Object> updateById(Integer id,String goodsname,String price,Integer num,String description){
//        goodsMapper.updateById(id, goodsname,price,num,description);

        public Map<String,Object> updateById(Cs cs){
        csMapper.updateById(cs);
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","更新成功!");
        return map;
    }
}
